package java_class_work.week05;

import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

/**
 * @Auther: admin
 * @Date: 2022/10/11 10:24
 * @Description: FileReader
 */
public class ReaderDemo {
    public static void main(String[] args) {
        String fileName = ".\\src\\java_class_work\\iotest\\writer.txt";
        Reader reader = null;
        try {
            reader = new FileReader(fileName);
            char[] chars = new char[1024];
            // 方式一：
            int temp, len = 0;
            while ((temp = reader.read()) != -1) {
                chars[len++] = (char) temp;
            }
            // 方式二：
            len = reader.read(chars);

            System.out.println(new String(chars, 0, len));

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (reader != null) reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
